package file;

import java.io.File;
import java.io.FileFilter;

public class Demo08_Test_FileFilter {
    public static void main(String[] args) {
        File file = new File("E:\\");

        File[] files = file.listFiles();
        //需求：得到所有.exe文件
        for (File file1 : files) {
            if (file1.isFile() && file1.getName().endsWith(".exe")) {
                System.out.println(file1.getAbsolutePath());
            }
        }
        System.out.println("********************************");
        //使用接口实现类
        File[] files1 = file.listFiles(new MyFilter());
        for (File file1 : files1) {
            System.out.println(file1);
        }

        System.out.println("*******************************");
        //使用Lambda表达式
        File[] files2 = file.listFiles(pathname -> pathname.isFile() &&
                pathname.getName().endsWith(".exe"));
        for (File file1 : files2) {
            System.out.println(file1);
        }

    }
}


class MyFilter implements FileFilter {

    @Override
    public boolean accept(File pathname) {
        return pathname.isFile() && pathname.getName().endsWith(".exe");
    }
}
